/**
 * 纯内容展示
 */
import React from 'react';
import styles from './index.less';

interface ContentProps {
  [key: string]: any;
}

/**
 * 中英文映射配置
 *
 * 举例：
 * {
 *    'resume': {
 *      value: '简历',
 *      render: value => React.ReactElement
 * }
 */
interface IConfigEnToCn {
  [key: string]: {
    value: string;
    render?: (data: any) => React.ReactElement;
  };
}

const renderPureContent = (content: ContentProps, config: IConfigEnToCn) => {
  if (!content) return null;

  if (config) {
    return Object.keys(config).map(key => (
      <div key={key} className={styles.infoItem}>
        <div className={styles.label}>{config[key].value}：</div>
        <div className={styles.desc}>
          {config[key].render ? config[key].render(content[key]) : content[key] || '暂无'}
        </div>
      </div>
    ));
  }

  return Object.keys(content).map(key => (
    <div key={key} className={styles.infoItem}>
      <div className={styles.label}>{key}：</div>
      <div className={styles.desc}>{content[key]}</div>
    </div>
  ));
};

export default renderPureContent;
